# import uuid

# from enum import Enum
# from pydantic import AnyUrl, BaseModel, EmailStr, Field, constr
#
#
# class MaleType(str, Enum):
#     MALE = 0
#     FEMALE = 1
#
#
# class UserModel(BaseModel):
#     id: uuid.UUID
#     name: str = Field(min_length=2, max_length=20)
#     account: constr(regex="^[A-Za-z0-9-_]+$", to_lower=True, strip_whitespace=True)
#     password: str = None
#     email: EmailStr
#     phone: str = None
#     male: MaleType = MaleType.MALE
#

from sqlalchemy import Boolean, Column, ForeignKey, Integer, String
from uuid import UUID, uuid4
from datetime import datetime
from models.base import Base
from pydantic import BaseModel, Field, constr, EmailStr


class UserScheme(Base):
    __tablename__ = "users"

    id: UUID = Column(String(50), primary_key=True, unique=True, nullable=False)
    username = Column(String(25), unique=False, nullable=False)
    account = Column(String(50), unique=True, nullable=False)
    password = Column(String(50), nullable=False)
    role = Column(String(50), unique=False, nullable=False)
    male = Column(Integer, nullable=False, default=0)
    email = Column(String(50), nullable=False)
    status = Column(Integer, default=1, nullable=False)
    create_time: datetime = Column()
    create_by: str = Column()
    update_time: datetime = Column()
    update_by: str = Column()


class UserLogin(BaseModel):
    username: str = Field(min_length=2, max_length=20)
    password: str


class UserCreate(UserLogin):
    password: str
    email: EmailStr
    male: int = 0
    status: int = 1


class UserUpdate(UserCreate):
    role: str


class User(UserUpdate):
    id: int = Field(default_factory=lambda: uuid4())
    create_time: datetime
    update_time: datetime
    update_by: str
    create_by: str
